#!/usr/bin/perl -w

#####################################################################
# Program Variables - Go see the central config.pm!
#####################################################################
use FindBin qw($Bin);
use lib "$Bin/..";
use config;
use layout;

#####################################################################
# Program Modules
#####################################################################
# CGI Modules
use CGI;
use CGI::Carp;
use CGI::Pretty;

# Database Module
use DBI;

#####################################################################
# Program Start
#####################################################################
my $cgi = new CGI;

my $pagetitle = &read_config_option("tank_name") . " Graphs";

my @graphs;

my $dbh = DBI->connect("dbi:SQLite:dbname=$database_file", "", "");
my $test_sth = $dbh->prepare("SELECT * FROM tests ORDER BY displayorder ASC");
$test_sth->execute();
while (my $testref = $test_sth->fetchrow_hashref()) {
    my %testhash = %{$testref};
    my $name     = $testhash{name};
    my $title    = $testhash{title};

    push(@graphs,
        $cgi->td([ $cgi->a({ -href => "showgraph.cgi?graph=$name" }, $cgi->img({ -src => "graphs/statistics-$name-day.png" }) . $cgi->br . $title) ])
    );
}
$dbh->disconnect();

# Web Page output
&ts_pagestart($pagetitle);

print $cgi->start_table(-align => "center");
print $cgi->Tr([@graphs]);
print $cgi->end_table;

print $cgi->p();
print $cgi->center("Return to the " . $cgi->a({ -href => "index.cgi" }, &read_config_option("tank_name") . " Index") . " Page.");
print $cgi->end_html;
print "\n";

# Okay, we're done, exit now.
exit 0;

